export default {
    toFormatString : function(fmt,time) {
        var o = {
            "M+": time.getMonth() + 1,                 //月份
            "d+": time.getDate(),                    //日
            "h+": time.getHours(),                   //小时
            "m+": time.getMinutes(),                 //分
            "s+": time.getSeconds(),                 //秒
            "q+": Math.floor((time.getMonth() + 3) / 3), //季度
            "S": time.getMilliseconds()             //毫秒
        };
        if (/(y+)/.test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (time.getFullYear() + "").substr(4 - RegExp.$1.length));
        }
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            }
        }
        return fmt;
    },
    //把int型的yyMMdd转换成字符串yy-MM-dd
    timeIntYMDToString:function(timeInt){
        let timeStr = String(timeInt);
        if (timeStr.length == 8) {
            let timeformat =  timeStr.slice(0,4) + "-" + timeStr.slice(4,6) + "-" + timeStr.slice(6,8)
            let date = new Date(timeformat);
            return this.toFormatString("yyyy-MM-dd",date);
        }else{
            if (timeStr == "null") {
                return "";
            }
            return timeStr;

        }
    },
    //把int型的yyMMdd转换成字符串yy-MM-dd hh:mm:ss
    timeIntToString:function(timeInt){
        let timeStr = String(timeInt);
        if (timeStr.length == 8) {
            let timeformat =  timeStr.slice(0,4) + "-" + timeStr.slice(4,6) + "-" + timeStr.slice(6,8)
            let date = new Date(timeformat);
            return this.toFormatString("yyyy-MM-dd hh:mm:ss",date)
        }else{
            return timeStr
        }
    },
    //date型字符串转string
    timeDateToString:function(time){
        let date = new Date(time);
        return this.toFormatString("yyyy-MM-dd hh:mm:ss",date)
    },
    //date型字符串转string
    timeDateToStringYMD:function(time){
        let date = new Date(time);
        return this.toFormatString("yyyy-MM-dd",date)
    },
    //date转Int
    timeDateStrToInt:function(time){
        let date = new Date(time);
        let dateStr = this.toFormatString("yyyyMMdd",date)
        return parseInt(dateStr);
    },
// date 代表指定的日期，格式：2018-09-27
// day 传-1表始前一天，传1表始后一天
// JS获取指定日期的前一天，后一天
    getNextDate:function(date, day) {
        let dd = new Date(date);
        dd.setDate(dd.getDate() + day);
        let y = dd.getFullYear();
        let m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
        let d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
        return y + "-" + m + "-" + d;
    },


}
